﻿using MySql.Data.MySqlClient;
using System;
using System.Windows;

namespace com.orange.examination
{
    public partial class WebForm9 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("../LoginAndRegister/Login.aspx");
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" || txtNum.Text == "" || txtPwd.Text == "")
            {
                Response.Write("<script>window.alert('请将信息填写完整！');</script>");
                return;
            }
            else
            {
                MySqlConnection conn = BaseClass.DBCon();
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("select count(*) from tb_Student where StudentNum='" + txtNum.Text + "'", conn);
                int i = Convert.ToInt32(cmd.ExecuteScalar());
                if (i > 0)
                {
                    
                    Response.Write("<script>window.alert('此学号已经存在！');</script>");
                    return;
                }
                else
                {
                    cmd = new MySqlCommand("insert into tb_Student(StudentNum,StudentName,StudentSex,StudentPwd) values('" + txtNum.Text.Trim() + "','" + txtName.Text.Trim() + "','" + rblSex.SelectedValue.ToString() + "','" + txtPwd.Text.Trim() + "')", conn);
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    Response.Write("<script>window.alert('添加成功！');</script>");
                    btnConcel_Click(sender, e);
                }
            }
        }
        protected void btnConcel_Click(object sender, EventArgs e)
        {
            txtName.Text = "";
            txtNum.Text = "";
            txtPwd.Text = "";
        }
    }
}